package mt.server;

import mt.comm.ServerComm;
import mt.dummy.ServerCommDummy;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

public class ServerTestUnit {

	/**
	 * Run the test suite.
	 *
	 */
	public static void main(String[] args) {
		Result result = JUnitCore.runClasses(ServerTestUnit.class);
		for (Failure failure : result.getFailures()) {
			System.out.println(failure.toString());
		}
		System.out.println(result.wasSuccessful());
	}

	/**
	 * Constructor test.
	 *
	 * @throws Exception
	 *
	 */
	@Test
	public void ServerConstructTest() throws Exception {
		Server result = new Server();
		Assert.assertNotNull(result);
	}


	/**
	 * Run the getActiveConnectionsNum() method test.
	 *
	 * @throws Exception
	 *
	 */
	@Test
	public void getActiveConnectionsNumTest() throws Exception {
		Server srv = new Server();
		assert(srv.getActiveConnectionsNum() >= 0);
	}

	/**
	 * Run the int getTransactionsNum() method test.
	 *
	 * @throws Exception
	 *
	 */
	@Test
	public void getTransactionsNumTest() throws Exception {
		Server srv = new Server();
		assert(srv.getTransactionsNum() >= 0);
	}

	/**
	 * Run the long getUpTime() method test.
	 *
	 * @throws Exception
	 *
	 */
	@Test
	public void getUpTimeTest() throws Exception {
		Server srv = new Server();
		long uptime = srv.getUpTime();
		assert(uptime < System.currentTimeMillis());
	}

	/**
	 * Run the void haltServer() method test.
	 *
	 * @throws Exception
	 *
	 */
	@Test
	public void haltServerTest() throws Exception {
		Server srv = new Server();
		srv.haltServer();
	}

	/**
	 * Run the void start(ServerComm) method test.
	 *
	 * @throws Exception
	 *
	 */
	@Test
	public void startTest() throws Exception {
		Server server = new Server();
		ServerComm serverComm = new ServerCommDummy(2020);
		server.start(serverComm);
	}
}